/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package net.worlds.ui;

import java.awt.Component;
import java.awt.image.BufferedImage;
import javax.swing.ImageIcon;
import javax.swing.JTree;
import javax.swing.tree.DefaultTreeCellRenderer;
import javax.swing.tree.TreeNode;
import net.worlds.AssetManager;


public class PartsTreeCellRenderer extends DefaultTreeCellRenderer{

    @Override
    public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus)
    {
        super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
        PartTreeNode node = (PartTreeNode)value;
        String objectType = null;
        if(node.toString() == null)
            objectType = "Unknown";
        else
        {
            objectType = ((PartTreeNode)node).getObject().getClass().getSimpleName();
        }

        BufferedImage image = AssetManager.getImage(objectType);
        if(image == null)
            image = AssetManager.getImage("Unknown");
        setIcon(new ImageIcon(image));
        return this;
    }
}
